package common.randcode;

import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.awt.image.BufferedImage;
import java.io.*;


public class VerificationCode {

    public static String getCode(String fileName) {
        File imageFile=new File("randCode\\img\\temp\\"+fileName);
        Tesseract tessreact = new Tesseract();
        tessreact.setDatapath("randCode\\tessdata");
        try {
            return tessreact.doOCR(imageFile);
        } catch (TesseractException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String getCode(BufferedImage img) {
        Tesseract tessreact = new Tesseract();
        tessreact.setDatapath("randCode\\tessdata");
        try {
            return tessreact.doOCR(img);
        } catch (TesseractException e) {
            e.printStackTrace();
            return null;
        }
    }
}
